# Makefile for example_json.c
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -I.
LIBS = -lcjson

# 检测操作系统
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
    # macOS
    CFLAGS += -I/opt/homebrew/include -I/usr/local/include
    LDFLAGS += -L/opt/homebrew/lib -L/usr/local/lib
endif

TARGET = example
SOURCE = example_json.c

SIMPLE_TARGET = simple_test
SIMPLE_SOURCE = simple_test.c

OPUS_TARGET = example_opus
OPUS_SOURCE = example_opus.c

all: $(TARGET) $(SIMPLE_TARGET) $(OPUS_TARGET) $(OPUS_ADV_TARGET)

$(TARGET): $(SOURCE)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(SOURCE) $(LIBS)

$(SIMPLE_TARGET): $(SIMPLE_SOURCE)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(SIMPLE_TARGET) $(SIMPLE_SOURCE) $(LIBS)

$(OPUS_TARGET): $(OPUS_SOURCE)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(OPUS_TARGET) $(OPUS_SOURCE) -lopus -lm

clean:
	rm -f $(TARGET) $(SIMPLE_TARGET) $(OPUS_TARGET) $(OPUS_ADV_TARGET)

install-deps:
	@echo "Installing cJSON library..."
ifeq ($(UNAME_S),Darwin)
	@echo "On macOS, install via Homebrew:"
	@echo "brew install cjson"
else
	@echo "On Ubuntu/Debian:"
	@echo "sudo apt-get install libcjson-dev"
	@echo "On CentOS/RHEL:"
	@echo "sudo yum install cjson-devel"
endif

run: $(TARGET)
	./$(TARGET)

.PHONY: all clean install-deps run
